//
// Parse.cpp for  in /home/goldbe_y//cpp/Maths/206observ
//
// Made by yoni goldberg
// Login   <goldbe_y@epitech.net>
//
// Started on  Mon May  2 15:13:56 2011 yoni goldberg
// Last update Fri Nov 23 18:45:37 2012 yoni goldberg
//

#include <cstdlib>
#include "Parse.hpp"
#include "convert.hpp"

std::string	Parse::epur(std::string tmp)
{
  int	i = 0;

  while (tmp[i])
    {
      if (tmp[i] == '\t')
	tmp[i] = ' ';
      i++;
      if (tmp[i] == ' ')
	tmp.erase(i, 1);
    }
  return (tmp);
}

Parse::Parse(const std::string &str)
{
  std::string			temp(" ");
  std::ifstream			file(str.c_str());

  if (file.is_open())
    {
      getline(file, temp);
      _dim = string_to_var<int>(epur(temp));
      _vecteurs = new float*[_dim];
      for (int i = 0; i < _dim; i++)
	_vecteurs[i] = new float[2];
      for (int i = 0; i < _dim; i++)
	{
	  std::string	tmp("");
	  getline(file, temp);
	  for (int j = temp.find_first_of("0123456789", 0); temp[j] != ' '; j++)
	    tmp+=temp[j];
	  _vecteurs[i][0] = string_to_var<float>(tmp);
	  int toto = tmp.size();
	  tmp = "";
	  for (int j = temp.find_first_of(" \t", toto); j < temp.size(); j++)
	    tmp += temp[j];
	  _vecteurs[i][1] = string_to_var<float>(tmp);	  
	}

      for (int i = 0; i < _dim; i++)
	std::cout << _vecteurs[i][0] << " | " << _vecteurs[i][1] << std::endl;
    }
}

Parse::~Parse()
{
}

int		Parse::get_dim() const
{
  return _dim;
}

float		**Parse::get_vecteurs() const
{
  return _vecteurs;
}
